$scriptDir = (split-path $myinvocation.mycommand.path -parent)

$dir = $env:windir + "\system32\inetsrv"

Set-Location $dir
$apps = .\appcmd.exe list config /section:system.webServer/fastCgi /xml

$foundImpersonate = $FALSE;
$foundPathInfo = $FALSE;
$foundForceRedirect = $FALSE;
$foundDocRoot = $FALSE;

$phpXml = [xml] $apps;
$applicationNodes = $phpXml.SelectNodes("//application[@fullPath[contains(.,'php-cgi.exe')]]");
$count = [int] $applicationNodes.Count;

if ($count -gt 0)
{
    $phpDir = [System.IO.Path]::GetDirectoryName($applicationNodes.Item(0).fullPath);  
}  

Set-Location $scriptDir

if ($phpDir -ne "")
{	
	$phpIni = [System.IO.Path]::Combine($phpDir, "php.ini");
    
    $value = ..\Common\Get-PrivateProfileString.ps1 "$phpIni" PHP fastcgi.impersonate
	if ($value -like "1*")
    {
        $foundImpersonate = $TRUE;
    }	
    
    $value = ..\Common\Get-PrivateProfileString.ps1 "$phpIni" PHP cgi.fix_pathinfo
	if ($value -like "1*")
    {
        $foundPathInfo = $TRUE;
    }	
    
    $value = ..\Common\Get-PrivateProfileString.ps1 "$phpIni" PHP cgi.force_redirect
	if ($value -like "0*")
    {
        $foundForceRedirect = $TRUE;
    }	
    
    $value = ..\Common\Get-PrivateProfileString.ps1 "$phpIni" PHP doc_Root
	if ($value -eq $null -OR $value -eq "")
    {
        $foundDocRoot = $TRUE;
    }	
}

$found = $foundImpersonate -AND $foundPathInfo -AND $foundForceRedirect -AND $foundDocRoot;

$found